<cfcomponent extends="AbsDAO" output="false">

	<cffunction name="create" access="public" returntype="Numeric" output="false">
		<cfargument name="permission" type="it.millemultimedia.easyBlog.model.Permission" required="true" />	
		<cfset var qry = "" />	
		<cfset var id = 0 />
		
		<cftransaction>
		
			<cfquery name="qry" datasource="#getDataSource().getName()#" username="#getDataSource().getUserName()#" password="#getDataSource().getPassword()#">
				INSERT INTO Permission
				(
					name,description
				)
				VALUES
				(
					<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#arguments.permission.getname()#" null="false" />,
				<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#arguments.permission.getdescription()#" null="false" />
				)
			</cfquery>
			
			<cfquery name="qry" datasource="#getDataSource().getName()#" username="#getDataSource().getUserName()#" password="#getDataSource().getPassword()#">
			SELECT MAX(idpermission) AS id
			FROM Permission
			</cfquery>
			
			<cfset id = qry.id />
		
		</cftransaction>

		<cfreturn id />
	</cffunction>
	
	<cffunction name="read" access="public" returntype="Query" output="false">
		<cfargument name="permission" type="it.millemultimedia.easyBlog.model.Permission" required="true" />
		<cfset var qry="" />
		
		<cfquery name="qry" datasource="#getDataSource().getName()#" username="#getDataSource().getUserName()#" password="#getDataSource().getPassword()#">
			SELECT idpermission,name,description
			FROM Permission
			WHERE idpermission = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.permission.getidPermission()#" null="false" />
		</cfquery>
		
		<cfreturn qry />
	</cffunction>
	
	<cffunction name="update" access="public" returntype="void" output="false">
		<cfargument name="permission" type="it.millemultimedia.easyBlog.model.Permission" required="true" />
		
		<cfset var qry="" />

		<cfquery name="qry" datasource="#getDataSource().getName()#" username="#getDataSource().getUserName()#" password="#getDataSource().getPassword()#">
			UPDATE Permission
			SET name = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#arguments.permission.getname()#" null="false" />,
				description = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#arguments.permission.getdescription()#" null="false" />
			WHERE idpermission = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.permission.getidPermission()#" null="false" />
		</cfquery>

	</cffunction>
	
	<cffunction name="delete" access="public" returntype="void" output="false">
		<cfargument name="permission" type="it.millemultimedia.easyBlog.model.Permission" required="true" />
		
		<cfset var qry="" />

		<cfquery name="qry" datasource="#getDataSource().getName()#" username="#getDataSource().getUserName()#" password="#getDataSource().getPassword()#">
			DELETE FROM Permission
			WHERE idpermission = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.permission.getidPermission()#" null="false" />
		</cfquery>
	</cffunction>
	
	
	<cffunction name="list" access="public" returntype="Query" output="false">
		<cfargument name="permission" type="it.millemultimedia.easyBlog.model.Permission" required="true" />
		
		<cfset var qry="" />

		<cfquery name="qry" datasource="#getDataSource().getName()#" username="#getDataSource().getUserName()#" password="#getDataSource().getPassword()#">
			SELECT * 
			FROM Permission
			WHERE idPermission is NOT NULL 
			<cfif !isNull( arguments.permission.getidPermission() ) >
			AND  idPermission = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.permission.getidPermission()#" null="false" />
			</cfif>
			
				
			<cfif !isNull( arguments.permission.getname() ) >
			AND  name = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#arguments.permission.getname()#" null="false" />
			</cfif>
			
				
			<cfif !isNull( arguments.permission.getdescription() ) >
			AND  description = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#arguments.permission.getdescription()#" null="false" />
			</cfif>
			
		</cfquery>
		
		<cfreturn qry/>
	</cffunction>

</cfcomponent>
